package com.xjw.controller;

import javax.annotation.Resource;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xjw.entity.User;
import com.xjw.entity.UserInfo;
import com.xjw.service.IUserService;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@EnableAutoConfiguration
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Resource
	IUserService userService;

    @RequestMapping("/{id}")
    public UserInfo view(@PathVariable("id") int id) {
        UserInfo user = new UserInfo();
        user.setName("zhang");
        return user;
    }
    
    @RequestMapping("/list/{pageIndex}")
    public ModelAndView list(@PathVariable("pageIndex") int pageIndex){
    	ModelAndView view = new ModelAndView();
    	view = new ModelAndView();
    	view.addObject("list", userService.getAllUser());
    	view.setViewName("list");
    	User user = userService.getUser("2");
    	return view;
    }
    

/*    public static void main(String[] args) {
        SpringApplication.run(UserController.class);
    }*/
}
